import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'

Vue.use (Router)

// No permission router
export const constantRoutes = [
    {
        path: '/login',
        component: () => import('@/views/Login/index'),
        hidden: true
    },
    {
        path: '/404',
        component: () => import('@/views/404'),
        hidden: true
    },
    {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
        children: [{
            path: 'dashboard',
            name: '首页',
            component: () => import('@/views/Dashboard/index'),
            meta: {title: '首页', icon: 'dashboard'}
        }]
    },
    /**
     * 权限管理部分宝库以下几个部分:
     * > 管理员管理
     * > 角色管理
     * > 节点管理
     * > 权限管理
     */
    {
        path: '/permission',
        component: Layout,
        redirect: '/index',
        meta: {
            title: '权限管理',
            icon: 'user'
        },
        children: [
            {
                path: '/index',
                component: () => import('@/views/permission'),
                meta: {
                    title: '账号权限管理',
                    icon: 'lock'
                }
            }, {
                path: '/router',
                component: () => import('@/views/permission/router'),
                meta: {
                    title: '路由节点管理',
                    icon: 'lock'
                }
            },
        ]
    },
    /**
     * 分类管理
     */
    {
        path: "/fenlei",
        component: Layout,
        redirect: '/fen',
        meta: {
            title: '分类管理',
            icon: 'component'
        },
        children: [
            {
                path: '/fen',
                component: () => import('@/views/fenlei/index'),
                meta: {
                    title: '分类管理',
                    icon: 'component'
                }
            }
        ]
    },
    {
        path: '/concat',
        component: Layout,
        redirect: '/concat',
        children: [
            {
                path: '/concat',
                component: () => import('@/views/lianxiwm/concat'),
                meta: {
                    title: "联系我们",
                    icon: 'peoples'
                }
            }
        ]
    },
    {
        path: '/shili',
        redirect: '/shili',
        component: Layout,
        children: [
            {
                path: '/shili',
                component: () => import('@/views/shili'),
                meta: {
                    title: '实例 / 素材管理',
                    icon: 'tab'
                }
            }
        ]
    },
    {
        path: '/banner',
        redirect: '/ban',
        component: Layout,
        children: [
            {
                path: '/ban',
                component: () => import('@/views/banner'),
                meta: {
                    title: '轮播管理',
                    icon: 'ban'
                }
            }
        ]
    },
    {
        path: '/know',
        redirect: '/know',
        component: Layout,
        children: [
            {
                path: '/know',
                component: () => import('@/views/daimazs'),
                meta: {
                    title: '问答/知识社区',
                    icon: 'ask'
                }
            }
        ]
    },
    {
        path: '/hot',
        redirect: '/hot',
        component: Layout,
        children: [
            {
                path: '/hot',
                component: () => import('@/views/remenht'),
                meta: {
                    title: '热门话题',
                    icon: 'talk'
                }
            }
        ]
    },
    {
        path: '/hz',
        redirect: '/hzxm',
        component: Layout,
        children: [
            {
                path: '/hzxm',
                component: () => import('@/views/hezuoxm'),
                meta: {
                    title: '合作项目',
                    icon: 'hz'
                }
            }
        ]
    },
    {
        path: '/hzhb',
        redirect: '/hzhb',
        component: Layout,
        children: [
            {
                path: '/hzhb',
                component: () => import('@/views/hezuoxm/hezuohb'),
                meta: {
                    title: '合作伙伴',
                    icon: 'hzhb'
                }
            }
        ]
    },
    {
        path: '/search',
        redirect: '/search',
        component: Layout,
        children: [
            {
                path: '/search',
                component: () => import('@/views/sousuojl'),
                meta: {
                    title: '搜索记录',
                    icon: 'searchjl'
                }
            }
        ]
    },
    {
        path: '/pl',
        redirect: '/pl',
        component: Layout,
        children: [
            {
                path: '/pl',
                component: () => import('@/views/pinglun'),
                meta: {
                    title: '评论管理',
                    icon: 'pl'
                }
            }
        ]
    },
    {path: '*', component: () => import('@/views/404')}
]

const createRouter = () => new Router ({
    mode: 'hash',
    scrollBehavior: () => ({y: 0}),
    routes: constantRoutes
})

const router = createRouter ()

export function resetRouter () {
    const newRouter = createRouter ()
    router.matcher = newRouter.matcher
}

export default router
